// miniprogram/pages/bmrs/bmrs.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:65
  },
  //点击选择-省份地市
  choisedishi() {
    var that = this;
    that.setData({
      bindpro: 1,
    })
  },
  //一级联动-省份
  dishi() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=40809&callback=?', //接收url
      data: {
        level: '1',
        dishi: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        //console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].dishi)
        }
        // console.log(list)
        that.setData({
          dishiList: list
        });
      }
    })
  },
  //点击选择-省份
  setdishi(e) {
    var that = this;
    console.log(e.currentTarget.dataset.dishi)
    that.setData({
      dishi: e.currentTarget.dataset.dishi
    })
    that.xianqu()
  },
  //点击重新选择-省份
  rechoisedishi() {
    var that = this;
    that.setData({
      xianquList: !1,
      xianqu: !1
    })
  },
  //二级联动-地市
  xianqu() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=40809&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'dishi',
        grtext: that.data.dishi
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].xianqu)
        }
        console.log(list)
        that.setData({
          xianquList: list
        });
      }
    })
  },
  //点击选择-地市
  setxianqu(e) {
    var that = this;
    console.log(e.currentTarget.dataset.xianqu)
    that.setData({
      xianqu: e.currentTarget.dataset.xianqu,
      xianquList: !1,
      bindpro: !1
    })
  },

  //点击选择-3级联动
  choisezhuguanbumen() {
    var that = this;
    if (that.data.xianqu) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=40809&callback=?', //接收url
        data: {
          level: '3',
          grfiled: 'xianqu',
          grtext: that.data.xianqu,
          onefiled: 'dishi',
          onetext: that.data.dishi
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          var list = [];
          for (var i in theJson.lists) { //循环写入下来框
            list.push(theJson.lists[i].zhuguanbumen)
          }
          console.log(list)
          that.setData({
            zhuguanbumenList: list,
            bindzhuguanbumen: 1
          });
        }
      })
    } else {
      wx.showToast({
        title: '请先选择地市',
        icon: 'none'
      })
    }

  },
  //点击选择-3级联动
  setzhuguanbumen(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zhuguanbumen)
    that.setData({
      zhuguanbumen: e.currentTarget.dataset.zhuguanbumen,
      bindzhuguanbumen: !1
    })
  },

  //点击选择-4级联动
  choisezhaopindanwei() {
    var that = this;
    if (that.data.zhuguanbumen) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=40809&callback=?', //接收url
        data: {
          level: '4',
          grfiled: 'zhuguanbumen',
          grtext: that.data.zhuguanbumen,
          onefiled: 'dishi',
          onetext: that.data.dishi,
          twofiled: 'xianqu',
          twotext: that.data.xianqu,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          var list = [];
          for (var i in theJson.lists) { //循环写入下来框
            list.push(theJson.lists[i].zhaopindanwei)
          }
          console.log(list)
          that.setData({
            zhaopindanweiList: list,
            bindzhaopindanwei: 1
          });
        }
      })
    } else {
      wx.showToast({
        title: '请先选择用人单位',
        icon: 'none'
      })
    }

  },
  //点击选择-4级联动
  setzhaopindanwei(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zhaopindanwei)
    that.setData({
      zhaopindanwei: e.currentTarget.dataset.zhaopindanwei,
      bindzhaopindanwei: !1
    })
  },
  //点击选择-5级联动
  choisegangweimingcheng() {
    var that = this;
    if (that.data.zhuguanbumen) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=40809&callback=?', //接收url
        data: {
          level: '5',
          grfiled: 'zhuguanbumen',
          grtext: that.data.zhuguanbumen,
          onefiled: 'dishi',
          onetext: that.data.dishi,
          twofiled: 'xianqu',
          twotext: that.data.xianqu,
          threefiled: 'zhuguanbumen',
          threetext: that.data.zhuguanbumen,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          var list = [];
          for (var i in theJson.lists) { //循环写入下来框
            list.push(theJson.lists[i].gangweimingcheng)
          }
          console.log(list)
          that.setData({
            gangweimingchengList: list,
            bindgangweimingcheng: 1
          });
        }
      })
    } else {
      wx.showToast({
        title: '请先选择用人单位',
        icon: 'none'
      })
    }

  },
  //点击选择-5级联动
  setgangweimingcheng(e) {
    var that = this;
    console.log(e.currentTarget.dataset.gangweimingcheng)
    that.setData({
      gangweimingcheng: e.currentTarget.dataset.gangweimingcheng,
      bindgangweimingcheng: !1
    })
  },
  closeselect() {
    var that = this;
    that.setData({
      bindpro: !1,
      bindzhaopindanwei: !1,
      bindgangweimingcheng: !1,
      bindzhuguanbumen: !1
    })
  },


  //个人信息查询提交
  submit() {
    var that = this;
    var phone = wx.getStorageSync('bmrdphone')
    if (phone) {
      if (that.data.xianqu && that.data.zhuguanbumen) {
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=40809&callback=?', //接收url
          data: {
            phone: phone,
            limits: 500,
            dishi: that.data.dishi,
            xianqu: that.data.xianqu,
            zhuguanbumen: that.data.zhuguanbumen,
            zhaopindanwei: that.data.zhaopindanwei,
            gangweimingcheng: that.data.gangweimingcheng
          }, //接收参数
          success(res) {
            wx.request({ //发送请求
              url: 'https://zg99.offcn.com/index/chaxun/register?actid=40809&callback=?', //接收url
              data: {
                phone: phone,
                fenxiao: that.data.fenxiao,
                geneal: that.data.geneal,
                dishi: that.data.dishi,
                xianqu: that.data.xianqu,
                zhuguanbumen: that.data.zhuguanbumen,
                zhaopindanwei: that.data.zhaopindanwei,
                gangweimingcheng: that.data.gangweimingcheng
              }, //接收参数
              success(res) {
                wx.request({ //发送请求
                  url: 'https://zg99.offcn.com/index/chaxun/gettotal?actid=40809&callback=?', //接收url
                  data: {
                    dishi: that.data.dishi,
                    xianqu: that.data.xianqu,
                    zhuguanbumen: that.data.zhuguanbumen,
                    zhaopindanwei: that.data.zhaopindanwei,
                    gangweimingcheng: that.data.gangweimingcheng
                  }, //接收参数
                  success(res) {
                    var jsonStr = res.data;
                    jsonStr = jsonStr.replace("(", "");
                    jsonStr = jsonStr.replace(")", "");
                    if (typeof jsonStr != 'object') {
                      jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                      var theJson = JSON.parse(jsonStr);
                    }
                    console.log(theJson)

                    that.setData({
                      rs: theJson.counts
                    })
                  }
                })

              }
            })
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            that.setData({
              lists: theJson.lists
            })
            wx.pageScrollTo({
              scrollTop: 500,
              duration: 600
            });

          }
        })
      } else {
        wx.showToast({
          title: '请完整填写信息',
          duration: 2000,
          icon: 'none'
        })
      }

    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        fixed: 1
      })
    }
  },

  
  getPhoneNumber(e) {
    var that = this;
    var fenxiao = that.data.area;
    var geneal = that.data.geneal;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('bmrdphone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=40809&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          that.setData({
            fixed: !1
          })
        }
      })

      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 30,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
    }).catch(err => {
      console.error(err);
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})